#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+2;
int T,n,m,L,V;
int d[maxn],v[maxn],a[maxn],p[maxn];
bool check[maxn];
inline int read(){
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*f;
}
struct node{
    int s222,degywu;
}a_1[1620];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T=read();
    while(T--){
        double loc=0.0;
        int ans1=0,ans2=0;
        int k=998244353;
        n=read(),m=read(),L=read(),V=read();
        for(int i=1;i<=n;i++)d[i]=read(),v[i]=read(),a[i]=read();
        for(int i=1;i<=m;i++)p[i]=read(),check[p[i]]==i;
        sort(p+1,p+n+1);
        sort(d+1,d+n+1);
        for(int i=1;i<=n;i++){
            //if(a[i]!=0)
            //loc=(3.0*3.0-v[i]*v[i]*1.0)/(2.0*a[i]);
            //else {
            if(d[1]>p[m])ans1--;
            if(d[n]<p[1])ans1--;
            if(v[i]>3){
                ans1++;
            }
            else {
                ans2=m;
            }
                //continue;
            //}
            //int k2=ans1,l;
            //float s=loc+d[i];
            /*for(int j=1;j<=m;j++){
                if(s<=p[j]){
                    if(a[i]>0){
                        if(ans1==k2)
                        ans1++;
                        int p1=0;
                        for(l=1;l<=m;l++){
                            if(s>p[l])p1++;
                        }
                        cout<<p1<<endl;
                    }
                    if(a[i]<0){
                        if(d[i]<=p[j]&&p[j]<=s&&v[i]>3)ans1++;
                        else //ans2=m-j;
                        break;
                    }
                }
                k=min(ans2,k);
            }*/

        }
        if(ans1!=0)
        printf("%d %d\n",ans1,ans2-1);
        else printf("%d %d\n",ans1,ans2);
    }//20?
    return 0;
}
